//
//  ObSignUpResponse.m
//
//  Created by   on 5/25/14
//  Copyright (c) 2014 __MyCompanyName__. All rights reserved.
//

#import "ObSignUpResponse.h"


NSString *const kObSignUpResponseMessage = @"Message";
NSString *const kObSignUpResponseStatus = @"Status";
NSString *const kObSignUpResponseDetails = @"details";


@interface ObSignUpResponse ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ObSignUpResponse

@synthesize message = _message;
@synthesize status = _status;
@synthesize details = _details;


+ (ObSignUpResponse *)modelObjectWithDictionary:(NSDictionary *)dict
{
    ObSignUpResponse *instance = [[ObSignUpResponse alloc] initWithDictionary:dict];
    return instance;
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.message = [self objectOrNilForKey:kObSignUpResponseMessage fromDictionary:dict];
            self.status = [self objectOrNilForKey:kObSignUpResponseStatus fromDictionary:dict];
            self.details = [self objectOrNilForKey:kObSignUpResponseDetails fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.message forKey:kObSignUpResponseMessage];
    [mutableDict setValue:self.status forKey:kObSignUpResponseStatus];
    [mutableDict setValue:self.details forKey:kObSignUpResponseDetails];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.message = [aDecoder decodeObjectForKey:kObSignUpResponseMessage];
    self.status = [aDecoder decodeObjectForKey:kObSignUpResponseStatus];
    self.details = [aDecoder decodeObjectForKey:kObSignUpResponseDetails];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_message forKey:kObSignUpResponseMessage];
    [aCoder encodeObject:_status forKey:kObSignUpResponseStatus];
    [aCoder encodeObject:_details forKey:kObSignUpResponseDetails];
}


@end
